<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2018/6/3
  Time: 16:20
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<html>
<head>
    <title>Title</title>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-3.3.1.js"></script>
    <script type="text/javascript">
        function onUpload() {
            // language=JQuery-CSS
            var obj = $('#uploadForm')[0];
            var formData = new FormData(obj);

            $.ajax({
                url: "${pageContext.request.contextPath}/fileUpLoad.do" ,
                type: 'POST',
                data: formData,
                dataType:"json",
                async: false,
                cache: false,
                contentType: false,
                processData: false,
                success: function (data) {
                    if(data.success){
                        alert("成功。。。");
                    }
                },
                error: function (data) {
                    alert(data);
                }
            });
        }
    </script>
</head>
<body>


<form action="${pageContext.request.contextPath}/fileUpLoad.do" enctype="multipart/form-data" method="post">
    文件描述： <input type="text" name="desc" value="" id="desc">
    <br>
    选择文件 ：
    <input type="file" name="file" id="file">
    <br>
    <input type="submit" value="提交">
</form>

<br>
<h1>以下使用ajax实现</h1>
<form id="uploadForm">
    文件描述： <input type="text" name="desc" value="" >
    <br>
    选择文件 ：
    <input type="file" name="file">
    <br>
    <input type="button" value="提交" onclick="onUpload()">
</form>

</body>


</html>
